export default {
	namespaced:true,
	state:()=>({
		cityName:'定位中...'
	}),
	mutations:{
		initCityName(state,name){
			state.cityName = name
		}
	},
	actions:{
		getCityAction(context){
			// context有什么特点？跟组件中 this.$store 具备相同能力
			uni.getLocation({
				success: ({longitude,latitude}) => {
					console.log(longitude,latitude);
					uni.request({
						url:`https://restapi.amap.com/v3/geocode/regeo?key=6c6f187b43a18982bb5a2e2dfa2399e6&location=${longitude},${latitude}`,
						success: (res) => {
							console.log(res);
							let {city,province} = res.data.regeocode.addressComponent
							let name = city.length?city:province
							context.commit('initCityName',name)
						}
					})
				}
			})
			
		}
	}
}